from flask_restx import Resource
from app_restful.restx import api
from app_restful.test.marshal_data import *
from flask import request
from models.user import TestUser
from extensions import db

test_namespace = api.namespace("test",description='测试')

@test_namespace.route('/test')
class Test(Resource):

    @api.marshal_with(test_response)
    def get(self):
        objs = TestUser.query.all()
        return objs

    @api.doc(params={
        'name': "名字"
    })
    @api.marshal_with(test_response)
    def post(self):
        name = request.args.get('name','')
        if name:
            obj = TestUser(name=name)
            db.session.add(obj)
            db.session.commit()
        return obj